<?php

/**
 * Description of ErrorHandler
 *
 * @author Ervinne
 */
class ErrorHandler {

    protected $errors = [];
    protected $all = [];

    public function add_error($error, $key = null) {
        if ($key) {
            $this->errors[$key][] = $error;
        } else {
            $this->errors[] = $error;
        }
    }

    public function all($key = null) {
//        echo $key;
        return isset($this->errors[$key]) ? $this->errors[$key] : $this->errors;
    }

    public function has_errors() {
        return count($this->errors) ? true : false;
    }

    public function first($key) {
        return isset($this->all()[$key][0]) ? $this->all()[$key][0] : '';
    }

}
